#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 渠道查询功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.trans.common.chn_query_service import ChnQueryService
from jlpay.model.trans.common.common_trans import (
    ChnQueryRequest, ChnQueryResponse
)


class ChnQueryExample(BaseExample):
    """渠道查询示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.common.chn_query")
        self.chn_query_service = ChnQueryService(self.config)
    
    def build_chn_query_request(self):
        """
        构建渠道查询请求
        
        Returns:
            ChnQueryRequest实例
        """
        request = ChnQueryRequest()
        
        # 设置请求参数
        request.set_mch_id("849584358120018")
        request.set_out_trade_no("20250327100002zyfTest")
        request.set_transaction_id("451138620256888383078402")
        
        return request
    
    def demo(self):
        """
        执行渠道查询示例
        """
        self.logger.info("开始执行渠道查询示例")
        
        # 创建渠道查询请求
        request = self.build_chn_query_request()
        
        # 发送请求
        response = self.send_request_and_handle_response(
            self.chn_query_service.chn_query,
            "渠道查询",
            request
        )
        
        self.logger.info("渠道查询示例执行完毕")


if __name__ == "__main__":
    logger = ChnQueryExample().logger
    logger.info("==================================================")
    logger.info("===== 渠道查询示例 开始 =====")
    logger.info("==================================================")
    
    example = ChnQueryExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 渠道查询示例执行完毕 =====")
    logger.info("==================================================") 